<?php

namespace app\user\controller;

use app\common\respond\HttpApi;
use app\user\logic\FactoryApplyLogic;

class FactoryApplyController
{
    /**
     * @Description 新增
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/29 11:04:06
     * @return \think\response\Json
     */
    public function add(HttpApi $respond)
    {
        $param = [
            'name' => request()->post('name'),
            'address' => request()->post('address'),
            'contacts' => request()->post('contacts'),
            'phone' => request()->post('phone'),
        ];
        $rule = [
            'name' => 'require|max:30',
            'address' => 'require|max:50',
            'contacts' => 'require|max:20',
            'phone' => 'require|mobile',
        ];
        validate($rule)->check($param);

        $logic = new FactoryApplyLogic();
        $data = $logic->add($param);

        return $respond->success([]);
    }

    /**
     * @Description 列表
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/29 11:46:46
     * @return \think\response\Json
     */
    public function list(HttpApi $respond)
    {
        $param = [
            'page' => (int)request()->get('page') ?: 1,
            'page_size' => (int)request()->get('page_size') ?: 10,
            'name' => request()->get('name'),
            'status' => request()->get('status')
        ];
        $rule = [
            'page' => 'require|integer|>:0',
            'page_size' => 'require|integer|>:0',
            'name' => 'max:255',
            'status' => 'integer|in:10,20,30'
        ];
        validate($rule)->check($param);

        $logic = new FactoryApplyLogic();
        $data = $logic->getList($param);

        return $respond->success($data);
    }

}